package com.ls.web;

import com.ls.entity.UserEntity;
import com.ls.mapper.test1.User1Mapper;
import com.ls.mapper.test2.User2Mapper;
import com.ls.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(value="/test", tags="测试接口模块")
@Controller
public class UserController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private User1Mapper user1Mapper;

    @Autowired
    private User2Mapper user2Mapper;

    @Autowired
    private UserService userService;

    @Value("${wx.appId}")
    private String appId;

    @Value("${wx.appKey}")
    private String appKey;

    @ApiOperation(value="展示用户信息", notes = "展示用户信息")
	@RequestMapping(value="/getUsers",method = RequestMethod.POST)
    @ResponseBody
	public List<UserEntity> getUsers() {

		List<UserEntity> users=userService.getAllUsers();
//		List<UserEntity> users=user1Mapper.getAll();
        logger.info(appId + "-" + appKey);
		return users;
	}

    @RequestMapping("/getUser")
    public UserEntity getUser(Long id) {
    	UserEntity user=user2Mapper.getOne(id);
        return user;
    }

    @ApiOperation(value="添加用户信息", notes = "添加用户信息")
    @ApiImplicitParam(name="user", value="User", required = true, dataType = "UserEntity")
    @RequestMapping("/add")
    public void save(UserEntity user) {
        user2Mapper.insert(user);
    }
    
    @RequestMapping(value="update")
    public void update(UserEntity user) {
        user2Mapper.update(user);
    }
    
    @RequestMapping(value="/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        user1Mapper.delete(id);
    }
    
    
}